Technical Q&A
OPS 19 - Making Data Executable (12-April-1999)
Q: I'm writing a program that constructs machine code on the fly. How do I correctly flush the processor cache so that I can execute the newly constructed instructions?
A: This answer depends on the instruction set architecture (ISA) of the code you are constructing:
- If you are constructing 68K code, you must call
FlushCodeCacheRange and, if that returns an error,
call FlushCodeCache .
- If you are constructing PowerPC code, you must call
MakeDataExecutable .
IMPORTANT:
The answer is independent of the ISA of the code you are
running. For example, if you're writing PowerPC code that
constructs 68K code, you must call
FlushCodeCacheRange and not
MakeDataExecutable . Similarly, if you are
writing 68K code that constructs PowerPC code, you must call
MakeDataExecutable .
|
WARNING:
You can not make 68K data executable using either
FlushInstructionCache or
FlushDataCache . To correctly make 68K data
executable, you must flush both caches in the right order.
FlushCodeCacheRange and
FlushCodeCache do this for you, which is why we
strongly recommend you use them exclusively.
For a detailed description of how the Macintosh cache
architecture affects software, see DTS Technote
HW
06 Cache as Cache Can.
|
The DTS sample code library "MoreIsBetter" contains a module
("MoreOSUtils") that shows how to make data executable as 68K or
PowerPC code. This module handles all of the complexities described
below.
There are a number of important things to remember when calling
the above routines:
For more information about instruction caches on the Macintosh,
see:
Thanks to Craig Prouse (DTS Emeritus) for reviewing this Q&A.
-- Quinn "The Eskimo!"
Worldwide Developer Technical Support
Technical Q&As | Contents
Previous Question | Next Question
To contact us, please use the Contact Us page.
|